import { isEmptyArr } from '../is';

export function digitalFormat(dataSets, blockType='') {
  const { dimensions, type, source, sourceMap = {} } = dataSets;
  let result = [];
  let [key] = Object.keys(sourceMap).length > 0 ? Object.keys(sourceMap) : [''];
  // IOT 数字翻牌器需要额外处理
  const valueKey =  type === 'STATIC' ? 'value' : dimensions?.yAxis;
  if (!isEmptyArr(source)) {
    const [item] = source;
    const value = item[valueKey] || item[key] ?  item[valueKey] || item[key] : 0;
    result =  blockType === 'iot' ? [{value:Number(value), date: item.ts, name: valueKey ||'' }]:[Number(value)];
  }
  return {
    seriesData: result
  };
}
